<?php
/**
 * Created by PhpStorm.
 * User: tangyunfei
 * Date: 2018/3/23
 * Time: 11:50
 */
class AreaAction extends  CommonAction{

    function index(){
        import('ORG.Util.Page');

        $count=M('Area')->count();// 查询总数据记录

        $Page = new Page($count,C('PAGESIZE'));

        $temp = M('Area')->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();

        $show= $Page->show();
        foreach ($temp as $v){
            $v['city'] = M('City')->where(array('id'=>$v['cityid']))->getField("city");
            $list[]=$v;
        }

        $this->assign("list",$list);

        $this->assign("page",$show);

        $this->display();
    }

    function add(){
        if(isset($_POST['submit'])){
               M('Area')->add($_POST);
               $this->success("操作成功",U('index'));
        }else{
            $this->province = M('City')->where(array('cid'=>0))->select();
            $this->display();
        }
    }

    function edit(){
        $id = I('get.id');
        if(isset($_POST['submit'])){
            M('Area')->where(array('id'=>$id))->save($_POST);
            $this->success("操作成功",U('index'));
        }else{
            $this->li = M('Area')->where(array('id'=>$id))->find();
            $this->province = M('City')->where(array('cid'=>0))->select();
            $this->display();
        }
    }
    
    function del(){
        $id = I('get.id');
        M('Area')->where(array('id'=>$id))->delete();
        $this->success("删除成功");
    }
}